package com.choosefine.base.shixiaobao.common.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.github.pagehelper.PageInfo;

/**
 * PageDto is a class designed for standard client-server communication.
 * In order to get a page of data list, client ought to send fixed parameters to server,
 * which are sort, direction, pageNum, pageSize.
 * @Author Ye_Wenda
 * @Date 2016/11/25 0025
 */
@JsonIgnoreProperties(value = {"size","startRow","endRow","firstPage","prePage","nextPage","lastPage","isFirstPage","isLastPage","hasPreviousPage","hasNextPage","navigatePages","sort","direction","navigatepageNums"})
public class PageInfoDTO<T> extends PageInfo<T> {

    public static String DIRECTION_ASC = "asc";

    public static String DIRECTION_DESC = "desc";

    /** 排序字段 */
    protected String sort;

    /** 升序/降序 */
    protected String direction;

    public PageInfoDTO() {
    }

    public PageInfoDTO(PageInfo pageInfo) {
        this.setPageNum(pageInfo.getPageNum());
        this.setPageSize(pageInfo.getPageSize());
        this.setPages(pageInfo.getPages());
        this.setTotal(pageInfo.getTotal());
        this.setOrderBy(pageInfo.getOrderBy());
        this.setList(pageInfo.getList());
    }

    public PageInfoDTO<T> convertPageInfo(PageInfo<T> page) {
        this.setList(page.getList());
        return this;
    }

    public String getSort() {
        return sort;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }

    public String getDirection() {
        return direction;
    }

    public void setDirection(String direction) {
        this.direction = direction;
    }
}
